package com.xyu.gulimall.search.controller;

import com.alibaba.fastjson.JSON;
import com.xyu.common.exception.BizCodeEnume;
import com.xyu.common.to.SkuEsModel;
import com.xyu.common.utils.R;
import com.xyu.gulimall.search.config.GulimallElasticsearchConfig;
import com.xyu.gulimall.search.contstant.EsContStant;
import com.xyu.gulimall.search.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/search/save")
@Slf4j
public class ElasticsearchSaveController {

    @Autowired
    private ProductService productService;

    @PostMapping("/product")
    public R ProductStatusUp(@RequestBody List<SkuEsModel> skuEsModels)  {
        System.out.println(skuEsModels);
        boolean b = false;

            try {
                b = productService.productStatusUp(skuEsModels);
            } catch (IOException e) {
                log.error("商品上架错误"+e);
                return R.error().put("error", BizCodeEnume.PRODUCT_UP_EXCEPTION.getMsg());
            }
        return R.ok();
    }
}
